package currentment;

import java.lang.reflect.Type;

public class deadLock {
    private static final Object o1 = new Object();
    private static final Object o2 = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            try {
                synchronized (o1) {
                    Thread.sleep(100);
                    System.out.println("对o1加锁");
                    synchronized (o2) {
                        System.out.println("尝试获得o2");
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, "t1");

        Thread t2 = new Thread(() -> {
            try {
                synchronized (o2) {
                    Thread.sleep(100);
                    System.out.println("对o2加锁");
                    synchronized (o1) {
                        System.out.println("尝试获得o1");
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, "t2");
        t1.start();
        t2.start();
    }

}
